Using view transforms
GLM can create many view transforms.
Camera
glm::lookAt(eye, center, up)
.
- eye: the position of the camera (vec3)
- center: the point to look at (vec3)
- up: the camera up direction (vec3)
- returns: mat4 camera matrix
Orthographic projection
glm::ortho(left, right, top, bottom, zNear, zFar)
.
- left, right, top, bottom, zNear, zFar: bounds of the view volume (float)
- returns: mat4 orthographic matrix
Note: near and far keywords are used by many compilers!
Perspective projection
glm::perspective(fovY, aspect, zNear, zFar)
.
- fovY: radians of vertical field of view (float)
- aspect: aspect ratio width/height (i.e. 16/9) (float)
- zNear, zFar: view volume bounds (float)
- returns: mat4 perspective matrix
- Note: near and far keywords are used by many compilers!
This projection includes the needed orthographic matrix.
Note: near and far keywords are used by many compilers!
Viewport transform
The 2D viewport can be set using:
glViewport(x, y, width, height)
- x: the position of the left side of the view
- y: the position of the bottom of the view
- width: how wide the view is
- height: how tall the view is